package com.lovo.javafxComponent;

import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Paint;

/**
 * 带标题容器
 * @author lenovo
 *
 */
public class LovoTitlePane extends Pane{
	
	/**
	 * 构造方法
	 * @param title 标题
	 * @param x X坐标
	 * @param y Y坐标
	 * @param width 宽度
	 * @param height 高度
	 * @param container 加入容器
	 */
	public LovoTitlePane(String title,int x,int y,
			int width,int height,Pane container) {
		Label titleLabel = new Label(title);
		titleLabel.setLayoutX(50);
		titleLabel.setLayoutY(-5);
		
		BackgroundFill backgroundFill = new BackgroundFill(Paint.valueOf("#f4f4f4"), new CornerRadii(20), Insets.EMPTY);
        Background background = new Background(backgroundFill);
		titleLabel.setBackground(background);
		
		this.setLayoutX(x);
		this.setLayoutY(y);
		this.setPrefSize(width, height);
		this.getChildren().add(titleLabel);
		this.setBorder(this.getViewBorder());
		
		container.getChildren().add(this);
	}
	
	private  Border getViewBorder() {
		return  new Border(new BorderStroke(Paint.valueOf("#00f"), 
				BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(2)));
	}
}
